from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
sleep(2)
driver.get("http://www.baidu.com")
sleep(2)
driver.maximize_window()
sleep(2)
#多窗口操作
ele=driver.find_element(By.LINK_TEXT,"新闻")
ele.click()
sleep(2)
#句柄:获取当前句柄
handle1 = driver.current_window_handle
ele=driver.find_element(By.LINK_TEXT,"贴吧")
ele.click()
sleep(2)
handle2 = driver.current_window_handle
ele=driver.find_element(By.LINK_TEXT,"文库")
ele.click()
sleep(2)
# 所有句柄列表
handles = driver.window_handles
for h in handles:
    if h!=handle1:
       driver.switch_to.window(h)
       sleep(2)
       if driver.title == "百度新闻——海量中文资讯平台":
           driver.find_element(By.PARTIAL_LINK_TEXT,"连续第五年").click()
           sleep(5)
sleep(2)
driver.quit()